Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

98
Vistas
What is the difference between "module.exports" and "exports.module" in java script

I have created a Model named 'Product' and the below code in there

const Sequelize = require('sequelize');

const sequelize = require('../util/database');

const Product = sequelize.define('product',{
    id: {
        type: Sequelize.INTEGER,
        autoincrement: true,
        allowNull: false,
        primaryKey: true
    },
    title: Sequelize.STRING,
    price: {
        type: Sequelize.DOUBLE,
        allowNull: false
    },
    imageUrl:{
        type: Sequelize.STRING,
        allowNull: true
    },
    description: {
        type: Sequelize.STRING,
        allowNull: true
    }
});

exports.module = Product;

I am getting the below error

Product.create is not a function

If I replace exports.module = Product; with module.exports = Product;, It is working good.

Can anyone clarify what is the difference between the two

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

module.exports is the property used to export values from a CommonJS module.

exports is a shorthand for module.exports.

exports.module is the same as module.exports.module which creates an value named module on the exported object.


So if you have:

module.exports = Product;

Then you would match it with:

const Product = require('./myModule');

But if you have:

exports.module = Product;

Then you would:

const myModule = require('./myModule');
const Product = myModule.module;

exports.module is, basically, a mistake and makes code confusing. Don't do that.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda